home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / archiver / lzhsourc.lzh / LZH.SRC / UTIL.C < prev   
C/C++ Source or Header  |  1992-07-02  |  4KB  |  203 lines

  1. /*************************************************
  2.         LHarc version 1.13 (c)Yoshi, 1988-89.
  3.         utility module : 1989/ 5/ 4
  4.  
  5.     adaption to ATARI ST with TURBO-C 1.1
  6.     by J. Moeller 1990/01/31
  7.  
  8. HTAB = 4
  9. *************************************************/
  10.  
  11. #include <stddef.h>
  12. #include <ctype.h>
  13.  
  14. #ifndef __TOS__
  15. #include <dos.h>
  16. #else
  17. #include <tos.h>
  18. #endif
  19.  
  20. typedef unsigned char uchar;
  21. typedef unsigned int  uint;
  22. typedef unsigned long ulong;
  23.  
  24. #ifdef Japanese
  25.  
  26. #define iskanji(c) ((uchar)(c) >= 0x80 && (uchar)(c) <= 0x9f || \
  27.             (uchar)(c) >= 0xe0 && (uchar)(c) <= 0xfd)
  28.  
  29. /*******************************
  30.     strupr for Japanese strings
  31. *******************************/
  32. uchar *j_strupr(uchar *p)
  33. {
  34.     uchar *q;
  35.  
  36.     for (q = p; *q; q++) {
  37.         if (iskanji(*q)) {
  38.             q++;
  39.             if (*q == 0)
  40.                 break;
  41.         } else {
  42.             *q = toupper(*q);
  43.         }
  44.     }
  45.     return p;
  46. }
  47.  
  48. /*******************************
  49.     strcmp for Japanese strings
  50. *******************************/
  51. int j_strcmp(char *p, char *q)
  52. {
  53.     int c, md0, md1;
  54.  
  55.     for (md0 = 0;
  56.          ((c = (uchar)*p - (uchar)*q) == 0) && (*p != 0); p++, q++) {
  57.         if (md0) {
  58.             md0 = 0;
  59.         } else {
  60.             md0 = iskanji((uchar)*p);
  61.         }
  62.     }
  63.     if (md0 == 0) {
  64.         md0  = iskanji((uchar)*p);
  65.         md1 = iskanji((uchar)*q);
  66.         if (md0) {
  67.             if (md1 == 0) return 1;
  68.         } else {
  69.             if (md1) return -1;
  70.         }
  71.     }
  72.     return c;
  73. }
  74.  
  75. /*******************************
  76.   strchr for Japanese strings
  77.     (subset of jstrchr)
  78.   can't search Kanji character
  79. *******************************/
  80. uchar *j_strchr(char *p, uint c)
  81. {
  82.     uchar *q, a;
  83.  
  84.     q = (uchar *)p;
  85.     while ((a = *q) != c) {
  86.         if (a == 0) return NULL;
  87.         if (iskanji(a)) {
  88.             if (*++q == 0) return NULL;
  89.         }
  90.         q++;
  91.     }
  92.     return q;
  93. }
  94.  
  95. /*******************************
  96.   strrchr for Japanese strings
  97.     (subset of jstrrchr)
  98.   can't search Kanji character
  99. *******************************/
  100. uchar *j_strrchr(char *p, uint c)
  101. {
  102.     uchar *q, *r;
  103.  
  104.     q = p - 1;
  105.     while ((r = j_strchr(q + 1, c)) != NULL) {
  106.         q = r;
  107.     }
  108.     if (q < p) return NULL;
  109.     return q;
  110. }
  111. #endif
  112.  
  113. /*******************************
  114.     get file attributes
  115. *******************************/
  116. int getfattr(uchar *fn)
  117. {
  118. #ifndef __TOS__
  119.     _DX = (uint)fn;
  120.     _CX = 0x8000;
  121.     _AX = 0x4300;
  122.     __int__(0x21);
  123.     return _CX;
  124. #else
  125.     return Fattrib (fn, 0, 0);
  126. #endif
  127. }
  128.  
  129. /*******************************
  130.     set file attributes
  131. *******************************/
  132. void setfattr(uchar *fn, int attr)
  133. {
  134. #ifndef __TOS__
  135.     _DX = (uint)fn;
  136.     _CX = attr;
  137.     _AX = 0x4301;
  138.     __int__(0x21);
  139. #else
  140.     Fattrib (fn, 1, attr);
  141. #endif
  142. }
  143.  
  144. /*******************************
  145.     get the setting of
  146.     switch character
  147. *******************************/
  148. #ifndef __TOS__
  149. uchar getswchar(void)
  150. {
  151.     _AX = 0x3700;
  152.     __int__(0x21);
  153.     return _DL;
  154. }
  155. #endif
  156.  
  157. /*******************************
  158.     convert '/' to '\'
  159.     ('\' code is assigned to
  160.     the Yen-mark in Japan.)
  161. *******************************/
  162. void slash2yen(uchar *p)
  163. {
  164.     for (; *p != '\0'; p++) {
  165.         if (*p == '/')
  166.             *p = '\\';
  167.     }
  168. }
  169.  
  170. void yen2slash(uchar *p)
  171. {
  172.     for (; *p != '\0'; p++) {
  173.         if (*p == '\\')
  174.             *p = '/';
  175.     }
  176. }
  177.  
  178. #ifdef __TOS__
  179. /*******************************
  180.     copy string and return
  181.     position of last character
  182. *******************************/
  183.  
  184. char *stpcpy (register char *dest, register char *source)
  185. {
  186.     if (source == NULL)
  187.         *dest++ = '\0';
  188.     else
  189.         while ((*dest++ = *source++) != '\0');
  190.  
  191.     return dest - 1;
  192. }
  193.  
  194. /*******************************
  195.     create a directory
  196. *******************************/
  197.  
  198. int mkdir (char *path)
  199. {
  200.     return Dcreate (path);
  201. }
  202. #endif
  203.